//
// Created by Administrator on 2023/10/8.
//
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

class Solution {
public:
    int numberOfPoints(vector<vector<int>> &nums) {
        int n = nums.size();
        unordered_set<int> s;
        for (int i = 0; i < n; ++i) {
            for (int j = nums[i][0]; j <= nums[i][1]; ++j) {
                s.insert(j);
            }
        }
        return s.size();
    }

    int numberOfPoints2(vector<vector<int>> &nums) {
        int diff[102]{};
        for (auto &p: nums) {
            diff[p[0]]++;
            diff[p[1] + 1]--;
        }
        int ans = 0, s = 0;
        for (int d: diff) {
            s += d;
            ans += s > 0;
        }
        return ans;
    }
};


int main() {
    vector<vector<int>> nums = {{3, 6},
                                {1, 5},
                                {4, 7}};
    Solution solution;
    int number = solution.numberOfPoints2(nums);
    cout << number << endl;
    return 0;
}